package oop.core.parsers;

import java.util.Scanner;

import oop.core.entity.Stats;

/**
 * used to save and load an avatars Stats in a formated string.
 * @author srhinson
 *
 */
public class StatsParser {
	static String del = "S~";
	
	public static String parseOut(Stats stats){
		String data = "";
		data=data.concat(stats.getExp()+del);
		data=data.concat(stats.getLives()+del);
		data=data.concat(stats.getHP()+del);
		data=data.concat(stats.getMP()+del);
		data=data.concat(stats.getStrength()+del);
		data=data.concat(stats.getAgility()+del);
		data=data.concat(stats.getIntellect()+del);
		data=data.concat(stats.getHardiness()+del);
		data=data.concat(Long.toString(stats.getMovement()));
		return data;
	}
	
	public static Stats parseIn(String data){
		Scanner scanner = new Scanner(data);
		scanner.useDelimiter(del);
		int xp =Integer.parseInt(scanner.next());
		int lives =Integer.parseInt(scanner.next());
		int hp =Integer.parseInt(scanner.next());
		int mp =Integer.parseInt(scanner.next());
		int str =Integer.parseInt(scanner.next());
		int agi =Integer.parseInt(scanner.next());
		int itl=Integer.parseInt(scanner.next());
		int hrd =Integer.parseInt(scanner.next());
		long move = Integer.parseInt(scanner.next());
		return new Stats(xp, lives, hp, mp, str, agi, itl, hrd, move);
		}

}
